package com.appspot.widget.auth;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.appspot.widget.base.BaseServlet;

public class AuthenticationServiceImpl extends BaseServlet {

	private static final long serialVersionUID = 6083183938411469997L;

	private static final String _USERNAME = "unity";
	private static final String _PASSWORD = "mbCla9832749";

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String username = req.getParameter("usr");
		String password = req.getParameter("pwd");

		if (username == null || username.trim().equals("")) {
			resp.setStatus(626);
			resp.getWriter().write("Username is required!");
			return;
		}
		if (password == null || password.trim().equals("")) {
			resp.setStatus(626);
			resp.getWriter().write("Password is required!");
			return;
		}

		if (_USERNAME.equals(username) && _PASSWORD.equals(password)){
			resp.getWriter().write("Authentication successful!");
			return;
		}
		else {
			resp.setStatus(626);
			resp.getWriter().write("Username or Password is incorrect!");
			return;
		}

	}

}
